#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""
语音文字识别
"""

import speech_recognition as sr

# 使用默认麦克风
recognizer = sr.Recognizer()

with sr.Microphone() as source:
    print("请开始说话...")
    audio = recognizer.listen(source)

try:
    # 将语音转换为文字
    text = recognizer.recognize_google(audio, language='zh-CN')
    print(f"你说的是: {text}")
except sr.UnknownValueError:
    print("无法理解语音")
except sr.RequestError as e:
    print(f"识别服务出错; {e}")